<!DOCTYPE html>
<html xmlns:>
<head>
<title>用户登录</title>
<meta name="keywords" content="" />
<meta name="description" content="">
<link rel="stylesheet" media="screen" href="__TMPL__/public/assets/css/login_style.css">
<link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/css/login_reset.css"/>

<include file="public@head_xy" />
<link href="__TMPL__/public/assets/toastr/toastr.css" rel="stylesheet" />
<script src="__TMPL__/public/assets/toastr/toastr.min.js"></script>
</head>

<body>
	<include file="public@nav" />
    <script>
        $(document).ready(function(){
            $("header").css("background-color","#060606");
            $(".head").css("background-color","#060606");
        });
    </script>
    <div id="particles-js">
        <div class="login xy_login">
            <div class="login-top">
                登录
            </div>
            <form>
                <div class="login-center clearfix">
                    <div class="login-center-img"><img src="__TMPL__/public/assets/images/name.png"/></div>
                    <div class="login-center-input">
                        <input type="text" name="username" value="" placeholder="请输入：手机号/邮箱/用户名" onfocus="this.placeholder=''" onblur="this.placeholder='请输入：手机号/邮箱/用户名'"/>
                        <div class="login-center-input-text">用户名</div>
                    </div>
                </div>
                <div class="login-center clearfix">
                    <div class="login-center-img"><img src="__TMPL__/public/assets/images/password.png"/></div>
                    <div class="login-center-input">
                        <input type="password" name="password" value="" placeholder="请输入您的密码" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的密码'"/>
                        <div class="login-center-input-text">密码</div>
                    </div>
                </div>
                <div class="login-center clearfix">
                    <div  id="xy_cap" class="login-center-input" style="width: 300px;margin-left: 0px;">
                        <input type="text" name="captcha" placeholder="验证码" class="form-control captcha" style="width: 100px; height:38px;float: left;margin-right: 30px">
                        <captcha height="38" width="150" font-size="15"/>
                    </div>
                </div>
                <div class="login-button">
                    登录
                </div>
            </form>
            <div class="xy_reg" style="text-align: center; color: #7b8a8b">
                <ul>
                    <li><a href="{:cmf_url('user/Register/index')}">现在注册</a></li>
                    <li style="margin-left:50px"><a href="{:cmf_url('user/Login/findPassword')}">忘记密码</a></li>
                </ul>
            </div>
        </div>
        <div class="sk-rotating-plane"></div>
    </div>
	<!-- /container -->
	<include file="public@scripts_xy" />
    <!-- scripts -->
    <script src="__TMPL__/public/assets/js/login_particles.min.js"></script>
    <script src="__TMPL__/public/assets/js/login_app.js"></script>
    <script type="text/javascript">
        toastr.options.positionClass = 'toast-top-center';
    </script>
    <script type="text/javascript">
        function hasClass(elem, cls) {
            cls = cls || '';
            if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
            return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
        }

        function addClass(ele, cls) {
            if (!hasClass(ele, cls)) {
                ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
            }
        }

        function removeClass(ele, cls) {
            if (hasClass(ele, cls)) {
                var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
                while (newClass.indexOf(' ' + cls + ' ') >= 0) {
                    newClass = newClass.replace(' ' + cls + ' ', ' ');
                }
                ele.className = newClass.replace(/^\s+|\s+$/g, '');
            }
        }

        function children(curEle,tagName){
            var nodeList = curEle.childNodes;
            var ary = [];
            if(/MSIE(6|7|8)/.test(navigator.userAgent)){
                for(var i=0;i<nodeList.length;i++){
                    var curNode = nodeList[i];
                    if(curNode.nodeType ===1){
                        ary[ary.length] = curNode;
                    }
                }
            }else{
                ary = Array.prototype.slice.call(curEle.children);
            }

            // 获取指定子元素
            if(typeof tagName === "string"){
                for(var k=0;k<ary.length;k++){
                    curTag = ary[k];
                    if(curTag.nodeName.toLowerCase() !== tagName.toLowerCase()){
                        ary.splice(k,1);
                        k--;
                    }
                }
            }

            return ary;
        }

        document.querySelector(".login-button").onclick = function(){
            addClass(document.querySelector(".login"), "active");
            setTimeout(function(){
                //addClass(document.querySelector(".sk-rotating-plane"), "active");
                document.querySelector(".login").style.display = "none"
            },800)
            setTimeout(function(){
                removeClass(document.querySelector(".login"), "active");
                removeClass(document.querySelector(".sk-rotating-plane"), "active");
                $.ajax({
                    type: 'post',
                    url: '{:url(\'user/login/doLogin\')}',
                    data: $("form").serialize(),
                    dataType: 'json',
                    success: function (data) {
                        var obj = eval(data);
                        if (obj.code == 1) {
                            //alert(obj.msg);
                            toastr.success(obj.msg);
                            //console.log(data);
                            setTimeout(function () {
                                window.history.go(-1);
                            },1000)
                        }
                        else if (obj.code == 0) {
                            var ele = document.getElementById('xy_cap');
                            //alert(obj.msg);
                            toastr.error(obj.msg);
                            document.querySelector(".login").style.display = "block";
                           // console.log(children(document.getElementById("xy_cap"),"img"));
                            //window.location.reload();
                            children(document.getElementById("xy_cap"),"img")[0].click();// 刷新下验证码
                        }
                        //console.log(data);
                    },
                    error: function () {
                        alert("无法连接到服务器：失败了！");
                        window.location.reload();//重新刷新页面
                    }
                });
                //alert("登录失败了")
            },2000);

        }

    </script>

</body>
</html>